package bajo.src;

import nanuk.ApplicationCredentials;
import nanuk.NanukApplication;

public class AppMain extends NanukApplication {
	
	public static ApplicationCredentials userCredentials;
	public static String applicationID = "61";
	
	public static AppMain theApp;
	
	public AppMain() {
	}
	
	// starts up the main client in the blackberry
	public static void main(String[] args) {
		theApp = new AppMain();
		try {
	       
	        //set value of secret if started with runtime argument --secret
	        if (args != null && args.length > 0 && args[0] != null){
				theApp.setSecret(args[0]);
	        }

	     	if (theApp.getSecret().compareTo("")==0) {
	     		// request secret and exit.  Control panel will restart application with 
	     		// secret as runtime argument
	     		theApp.requestSecret();
	    		theApp.exit();
	    		System.exit(0);
	     	}
	     	
	     	// Obtain current user credentials for this application
	     	userCredentials = theApp.requestUserCredentials();
		
//			theApp.showLoadingScreen(credentials.getLogin());
			theApp.showMainPage(userCredentials.getLogin());
		} 
		catch (final Exception e) {
			System.exit(1);
		}
	}

	public void exit() {
		// TODO Auto-generated method stub
		
	}

	public String getApplicationId() {
		return applicationID;
	}

	public void invalidateCredentials() {
		// TODO Auto-generated method stub
		
	}
	
	private void showMainPage(String userID){
		MainPage mp = new MainPage(userID);
		pushScreen(mp);
		enterEventDispatcher();
	}
	
	private void showLoadingScreen(String userID){
		LoadingScreen ls = new LoadingScreen(userID); 
		pushScreen(ls);
		enterEventDispatcher();	
		ls.load();
	}
	
}